package com.situ.mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.situ.mall.mapper.ProductMapper;
import com.situ.mall.pojo.bo.ProductSearchBO;
import com.situ.mall.pojo.entity.Product;
import com.situ.mall.service.IProductService;
import com.situ.mall.util.JSONResult;

@Service
public class ProductServiceImpl implements IProductService{
	@Autowired
	private ProductMapper productMapper;

	@Override
	public JSONResult selectByPage(ProductSearchBO productSearchBO, Integer page, Integer limit) {
		int offset = (page - 1) * limit;
		List<Product> list = productMapper.selectByPage(productSearchBO, offset, limit);
		int count = productMapper.selectTotalCount(productSearchBO);
		
		return JSONResult.ok(list, count);
	}

	@Override
	public boolean insert(Product product) {
		int count = productMapper.insert(product);
		return count == 1;
	}

	@Override
	public Product selectById(Integer productId) {
		return productMapper.selectByPrimaryKey(productId);
	}

}
